class StringNumber:
    # 参与进制的字符集
    _chars = []
    # 进制
    _system = 0
    _str_value = '0'
    _num_value = 0

    def __init__(self):
        for i in range(10):
            self._chars.append(str(i))
        for i in range(26):
            self._chars.append(chr(i + 65))
        for i in range(26):
            self._chars.append(chr(i + 97))
        self._system = self._chars.__len__()

    def set_num_value(self, num):
        self._num_value = num
        self._str_value = StringNumber.__num2str(self._num_value, self._chars)

    def set_str_value(self, string):
        self._str_value = string
        self._num_value = StringNumber.__str2num(string, self._system, self._chars)

    def str_value(self):
        return self._str_value

    def num_value(self):
        return self._num_value

    def add_one(self):
        self._num_value += 1
        self._str_value = StringNumber.__num2str(self._num_value, self._system)

    def add(self, other):
        self._num_value += other
        self._str_value = StringNumber.__num2str(self._num_value, self._system)

    def sub_one(self):
        self._num_value -= 1
        self._str_value = StringNumber.__num2str(self._num_value, self._system)

    def sub(self, other):
        self._num_value -= other
        self._str_value = StringNumber.__num2str(self._num_value, self._system)

    @staticmethod
    def __num2str(num, system):
        chs = []
        n = num
        while True:
            dd = int(n / system)
            cc = n % system

            ch = StringNumber.__num2char(cc, system)
            chs.append(ch)

            if dd == 0:
                break

            n = dd

        chs.reverse()
        return ''.join(chs)

    @staticmethod
    def __str2num(string, system, chars):
        l = len(string)
        num = 0
        i = 1
        for ch in string:
            if chars.__contains__(ch):
                n = StringNumber.__char2num(ch)
                num += n * pow(system, l - i)
                i += 1
            else:
                return -1
        return num

    @staticmethod
    def __char2num(ch):
        if len(ch) == 1:
            n = ord(ch)
            if 48 <= n <= 57:
                return n - 48
            elif 65 <= n <= 90:
                return n - 55
            elif 97 <= n <= 122:
                return n - 61

        return -1

    @staticmethod
    def __num2char(num, system):
        if -1 < num < system:

            if 0 <= num <= 9:
                return chr(num + 48)
            elif 10 <= num <= 35:
                return chr(num + 55)
            elif 36 <= num <= system:
                return chr(num + 61)

        return '_'

# sn = StringNumber()
# sn.set_str_value('9')
# print(sn.str_value(), sn.num_value())
#
# sn.add_one()
# print(sn.str_value(), sn.num_value())
#
#
# sn.sub_one()
# print(sn.str_value(), sn.num_value())
#
#
# sn.sub(54)
# print(sn.str_value(), sn.num_value())
